import { createStore } from 'vuex'
import userManage from './user/index.ts'
import userCenter from './userCenter/index.ts'
import register from './register/index.ts'

export default createStore({
    state:{
        isCollapse:true ,
        breadcrumbNavigation: null,
        tabsList :[
           {
            path: '/home',
            name: 'home',
            title: '首页',
            icon: 'home'
           }
        ],
       lang: localStorage.getItem('lang') || 'zh'   //持久化语言
    },
    mutations:{
        updateIsCollapse(state,payload){
            state.isCollapse = !state.isCollapse
        },
        selectMenu(state,val){
            // val.name === 'home' ? (state.breadcrumbNavigation = null) : (state.breadcrumbNavigation = val)
            // console.log('1111',val.name)
            if(val.name === 'home'){
                state.breadcrumbNavigation = null
            }else{
                state.breadcrumbNavigation = val
                let result = state.tabsList.findIndex(item =>item.name === val.name)
                result === -1 ? state.tabsList.push(val) : ''
            }
        },
        closeTab(state,val){
            let res = state.tabsList.findIndex(item=>item.name === val.name)
            state.tabsList.splice(res,1)
        },
        changLang(state,val){
            state.lang = val    //修改语言
        }
    },
    modules:{
        userManage,
        userCenter,
        register
    }
})